

#include <unistd.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <stdarg.h>
#include <sys/time.h>
#include <sched.h>
#include <pthread.h>
#include <arpa/inet.h>

#include "../src/include/log.h"
#include "../src/include/bitmap.h"
#include "../src/include/list.h"
#include "../src/include/rbtree.h"
#include "../src/include/acl.h"
#include "../src/include/aclmgr.h"
#include "tc_acl.h"


typedef struct tagDBG_RBT_NODE_S 
{
	struct rb_node stNode;
	unsigned int uiKey;	
	unsigned int uiValue;
} DBG_RBT_NODE_S;

unsigned int g_uiSucc;
unsigned int g_uiFail;
volatile unsigned int g_uiThreadFlag;
unsigned int ITEM_COUNT_PER_RULE = 1;

inline unsigned long long GET_MicroSec()
{
	unsigned long long uiUSecond;
	struct timeval stTime;
	
	gettimeofday(&stTime, NULL);
	uiUSecond = (stTime.tv_sec*1000) + (stTime.tv_usec/1000);

	return uiUSecond;
}

void SET_RUN_CPU(unsigned int uiCpu)
{
	cpu_set_t stCpuSet;
	CPU_ZERO(&stCpuSet);
	CPU_SET(uiCpu, &stCpuSet);
	sched_setaffinity(pthread_self(), sizeof(cpu_set_t), &stCpuSet);
}

int RbtCompare(struct rb_node *pstNew, const struct rb_node *pstMember)
{
	DBG_RBT_NODE_S *pstNewNode = rb_entry(pstNew, DBG_RBT_NODE_S, stNode);
	DBG_RBT_NODE_S *pstMemberNode = rb_entry(pstMember, DBG_RBT_NODE_S, stNode);

	if (pstNewNode->uiKey == pstMemberNode->uiKey)
	{
		return RBT_EQUAL;
	}
	else if (pstNewNode->uiKey < pstMemberNode->uiKey)
	{
		return RBT_LESS;
	}
	else
	{
		return RBT_GREAT;
	}
}

void RbtNodeFree(struct rb_node *pNode)
{
	DBG_RBT_NODE_S *pstNode = rb_entry(pNode, DBG_RBT_NODE_S, stNode);
	//printf("RBT_DELETE: <%u/%u>\n", pstNode->uiKey, pstNode->uiValue);
	free(pstNode);
}

unsigned int RBT_FindInt(const struct rb_root *root, unsigned int uiKey)
{
	DBG_RBT_NODE_S *pstNode;
	struct rb_node *pstRbtNode;
	DBG_RBT_NODE_S stKeyNode;
	unsigned int uiValue = 0;

	if (root)
	{
		stKeyNode.uiKey = uiKey;
		pstRbtNode = rb_find(&(stKeyNode.stNode), root, RbtCompare);
		if (NULL != pstRbtNode)
		{
			pstNode = rb_entry(pstRbtNode, DBG_RBT_NODE_S, stNode);
			uiValue = pstNode->uiValue;
		}
	}

	return uiValue;
}

void TEST_CFG_AddRule_Basic()
{
    unsigned int iIndex = 0;
    char szRuleName[100];

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
    }
    TEST_PRINT_OUT("RULE_ADD %d count", TEST_RULE_CNT);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    TEST_CHECK_INT("[PRIORITY] test1", 1, RULE_PRIORITY("test1"));
    TEST_CHECK_INT("[PRIORITY] test7", 7, RULE_PRIORITY("test7"));
    TEST_CHECK_INT("[PRIORITY] test10", 10, RULE_PRIORITY("test10"));
    TEST_CHECK_INT("[PRIORITY] test11", RULE_INVALID_PRIORITY, RULE_PRIORITY("test11"));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("[PRIORITY] test10", RULE_INVALID_PRIORITY, RULE_PRIORITY("test10"));
    TEST_CHECK_INT("[GET_RULE] COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_CFG_AddRule_Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    TEST_CHECK_INT("[PRIORITY] test100000", 100000, RULE_PRIORITY("test100000"));
    TEST_CHECK_INT("[PRIORITY] test200000", RULE_INVALID_PRIORITY, RULE_PRIORITY("test200000"));
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("[GET_RULE] COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_CFG_DelRule_Basic()
{
    unsigned int iIndex = 0;
    char szRuleName[100];

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
    }
    TEST_PRINT_OUT("RULE_ADD %d count", TEST_RULE_CNT);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_CHECK_INT("[PRIORITY] test1", 1, RULE_PRIORITY("test1"));
    TEST_CHECK_INT("[PRIORITY] test7", 7, RULE_PRIORITY("test7"));
    TEST_CHECK_INT("[PRIORITY] test10", 10, RULE_PRIORITY("test10"));
    TEST_CHECK_INT("[PRIORITY] test11", RULE_INVALID_PRIORITY, RULE_PRIORITY("test11"));

    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_DEL(szRuleName);
        RULE_PRINT_CFG();
    }
    
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("[PRIORITY] test10", RULE_INVALID_PRIORITY, RULE_PRIORITY("test10"));
    TEST_CHECK_INT("[GET_RULE] COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_CFG_DelRule_Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    TEST_CHECK_INT("[PRIORITY] test100000", 100000, RULE_PRIORITY("test100000"));
    TEST_CHECK_INT("[PRIORITY] test200000", RULE_INVALID_PRIORITY, RULE_PRIORITY("test200000"));

    tStart = GET_MicroSec();
    unsigned int DEL_CNT = (TEST_RULE_CNT/100);
    for (iIndex = 1; iIndex <= DEL_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_DEL(szRuleName);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_DEL %d count cost %llu ms (rate=%u/s)", 
    				DEL_CNT, tDiff, GET_Rate(DEL_CNT,tDiff));				
    TEST_CHECK_INT("RULE_COUNT", (TEST_RULE_CNT-DEL_CNT), RULE_COUNT());
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_CFG_DelRule_Speed_Reverse()
{
	unsigned int iIndex = 0;
	char szRuleName[100];
	unsigned long long tStart;
	unsigned long long tDiff;

	TEST_START();

	unsigned int TEST_RULE_CNT = 100000;
	tStart = GET_MicroSec();
	for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
	{
		sprintf(szRuleName, "test%d", iIndex);
		RULE_ADD(szRuleName);
	}
	tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)",
					TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));    				
	TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
	//RULE_PRINT_CFG();

	TEST_CHECK_INT("[PRIORITY] test100000", 100000, RULE_PRIORITY("test100000"));
	TEST_CHECK_INT("[PRIORITY] test200000", RULE_INVALID_PRIORITY, RULE_PRIORITY("test200000"));

	tStart = GET_MicroSec();
	unsigned int DEL_CNT = (TEST_RULE_CNT-1);
	for (iIndex = DEL_CNT; iIndex >= 1; iIndex--)
	{
		sprintf(szRuleName, "test%d", iIndex);
		RULE_DEL(szRuleName);
	}
	tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("!RULE_DEL %d count cost %llu ms (rate=%u)", 
					DEL_CNT, tDiff, GET_Rate(DEL_CNT,tDiff)); 
	TEST_CHECK_INT("RULE_COUNT", (TEST_RULE_CNT-DEL_CNT), RULE_COUNT());
	
	RULE_DEL_ALL();
	TEST_PRINT_OUT("RULE_DEL_ALL"); 
	TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
	RULE_PRINT_CFG();

    TEST_END();
}

/*
void TEST_CFG_Append_Obj_Basic()
{
    unsigned int iIndex = 0;
    char szRuleName[100];

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
    }
    TEST_PRINT_OUT("RULE_ADD %d count", TEST_RULE_CNT);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj1", OBJECT_1, 1, "test1");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj7", OBJECT_1, 7, "test7");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj10", OBJECT_1, 10, "test10");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj11", OBJECT_1, 11, "");

    RULE_DEL_ALL(); 
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_CFG_DelRule_WithObj_Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));    
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    TEST_CHECK_INT("[PRIORITY] test100000", 100000, RULE_PRIORITY("test100000"));
    TEST_CHECK_INT("[PRIORITY] test200000", RULE_INVALID_PRIORITY, RULE_PRIORITY("test200000"));

    tStart = GET_MicroSec();
    #define DEL_CNT  (TEST_RULE_CNT/100)
    for (iIndex = 1; iIndex <= DEL_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_DEL(szRuleName);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_DEL %d count cost %llu ms (rate=%u/s)", 
    				DEL_CNT, tDiff, GET_Rate(DEL_CNT,tDiff));
    TEST_CHECK_INT("RULE_COUNT", (TEST_RULE_CNT-DEL_CNT), RULE_COUNT());

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}
*/
void TEST_CFG_Append_SrcIPv4_Basic()
{
    unsigned int iIndex = 0;
    char szRuleName[100];

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    TEST_PRINT_OUT("RULE_ADD %d count", TEST_RULE_CNT);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();
    RULE_SAVE_DEFAULT();

    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj1", IPV4_START+1, "test1");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj7", IPV4_START+7, "test7");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj10", IPV4_START+10, "test10");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj11", IPV4_START+11, "");

    RULE_DEL_ALL(); 
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_CFG_Append_SrcIPv4_Basic_Range2()
{
    unsigned int iIndex = 0;
    char szRuleName[100];

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex+1);
    }
    TEST_PRINT_OUT("RULE_ADD %d count", TEST_RULE_CNT);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();
    RULE_SAVE_DEFAULT();

    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj1", IPV4_START+1, "test1");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj7", IPV4_START+7, "test6");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj10", IPV4_START+10, "test9");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj11", IPV4_START+11, "test10");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj12", IPV4_START+12, "");

    RULE_DEL_ALL(); 
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}
/*
void TEST_CFG_SAVE_WithObject()
{
    unsigned int iIndex = 0;
    char szRuleName[100];

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    TEST_PRINT_OUT("RULE_ADD %d count", TEST_RULE_CNT);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    RULE_PRINT_CFG();
    RULE_SAVE_DEFAULT();

    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj1", OBJECT_1, 1, "test1");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj7", OBJECT_1, 7, "test7");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj10", OBJECT_1, 10, "test10");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj11", OBJECT_1, 11, "");

    RULE_DEL_ALL(); 
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}
*/
/*
void TEST_MATCH_Normal_Obj_Basic()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj1", OBJECT_1, 1, "test1");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj88888", OBJECT_1, 88888, "test88888");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj100000", OBJECT_1, 100000, "test100000");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj200000", OBJECT_1, 200000, "");

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_Obj_Any()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 90000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)",
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj1", OBJECT_1, 1, "test1");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj88888", OBJECT_1, 88888, "test88888");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj100000", OBJECT_1, 100000, "test90000");
    TEST_CHECK_OBJ_NORMAL_MATCH("[NORMAL_MATCH] obj200000", OBJECT_1, 200000, "test90000");

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_Obj_BestSpeed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));    
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*2000);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_OBJ(OBJECT_1, 1);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] BEST %d count cost %llu ms (rate=%u/s)",
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_Obj_10Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)",
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*1000);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_OBJ(OBJECT_1, 10);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] 10Speed %d count cost %llu ms (rate=%u/s)",
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT,tDiff));
	
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_Obj_20Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*500);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_OBJ(OBJECT_1, 20);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] 20Speed %d count cost %llu ms (rate=%u/s)",
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT,tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_Obj_50Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)",
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*300);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_OBJ(OBJECT_1, 50);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] 50Speed %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT,tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_Obj_100Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*200);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_OBJ(OBJECT_1, 100);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] 100Speed %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT,tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_Obj_1000Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = TEST_RULE_CNT*20;
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_OBJ(OBJECT_1, 1000);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] 1000Speed %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT,tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_Obj_WorstSpeed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT,tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT/200);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_OBJ(OBJECT_1, (TEST_RULE_CNT-iIndex));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] WORST %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT,tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}
*/

void TEST_MATCH_Normal_SrcIPv4_Basic()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));    				
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj1", IPV4_START+1, "test1");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj88888", IPV4_START+88888, "test88888");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj100000", IPV4_START+100000, "test100000");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj200000", IPV4_START+200000, "");

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_DestIPv4_Basic()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));    				
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    CHECK_DEST_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj1", IPV4_START+1, "test1");
    CHECK_DEST_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj88888", IPV4_START+88888, "test88888");
    CHECK_DEST_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj100000", IPV4_START+100000, "test100000");
    CHECK_DEST_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj200000", IPV4_START+200000, "");

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_SrcIPv4_Any()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 90000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj1", IPV4_START+1, "test1");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj88888", IPV4_START+88888, "test88888");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj100000", IPV4_START+100000, "test90000");
    CHECK_SRC_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj200000", IPV4_START+200000, "test90000");

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_DestIPv4_Any()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 90000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    CHECK_DEST_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj1", IPV4_START+1, "test1");
    CHECK_DEST_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj88888", IPV4_START+88888, "test88888");
    CHECK_DEST_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj100000", IPV4_START+100000, "test90000");
    CHECK_DEST_IPV4_NORMAL_MATCH("[NORMAL_MATCH] obj200000", IPV4_START+200000, "test90000");

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_SrcIPv4_BestSpeed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*1000);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_SRC_IPV4((IPV4_START+1));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] BEST %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_DestIPv4_BestSpeed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*1000);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_DEST_IPV4((IPV4_START+1));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] BEST %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_SrcIPv4_10Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));   
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*500);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_SRC_IPV4((IPV4_START+10));
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![NORMAL_MATCH] 10Speed %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_DestIPv4_10Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));   
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*500);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_DEST_IPV4((IPV4_START+10));
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![NORMAL_MATCH] 10Speed %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_SrcIPv4_20Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*500);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_SRC_IPV4((IPV4_START+20));
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![NORMAL_MATCH] 20Speed %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_DestIPv4_20Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*500);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_DEST_IPV4((IPV4_START+20));
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![NORMAL_MATCH] 20Speed %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_SrcIPv4_50Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*100);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_SRC_IPV4((IPV4_START+50));
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![NORMAL_MATCH] 50Speed %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_DestIPv4_50Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*100);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_DEST_IPV4((IPV4_START+50));
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![NORMAL_MATCH] 50Speed %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_SrcIPv4_100Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*50);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_SRC_IPV4((IPV4_START+100));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] 100Speed %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_DestIPv4_100Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT*50);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_DEST_IPV4((IPV4_START+100));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] 100Speed %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_SrcIPv4_1000Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = TEST_RULE_CNT;
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_SRC_IPV4((IPV4_START+1000));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] 1000Speed %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_DestIPv4_1000Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = TEST_RULE_CNT;
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_DEST_IPV4((IPV4_START+1000));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] 1000Speed %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_SrcIPv4_WorstSpeed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
   	TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT/100);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_SRC_IPV4((IPV4_START+TEST_RULE_CNT-iIndex));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] WORST %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_MATCH_Normal_DestIPv4_WorstSpeed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    tDiff = GET_MicroSec()-tStart;
   	TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    unsigned int MATCH_CNT = (TEST_RULE_CNT/100);
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        MATCH_FIRST_RULE_BY_DEST_IPV4((IPV4_START+TEST_RULE_CNT-iIndex));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![NORMAL_MATCH] WORST %d count cost %llu ms (rate=%u/s)", 
					MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

/*
void DBG_RBT_Operate()
{
	DBG_RBT_NODE_S *pstNode;
	struct rb_node *pstRbtNode;	
	struct rb_root stRbtRoot = RB_ROOT;
	unsigned int uiIndex;
	unsigned int MULTI_CNT = 6;
	unsigned long long tStart;
	
	for (uiIndex = 1; uiIndex <= 10; uiIndex++)
	{
		pstNode = (DBG_RBT_NODE_S *)malloc(sizeof(DBG_RBT_NODE_S));
		pstNode->uiKey = uiIndex;
		pstNode->uiValue = pstNode->uiKey*MULTI_CNT;
		rb_add(&(pstNode->stNode), &stRbtRoot, RbtCompare);
		printf("RBT_INSERT: <%u/%u>\n", pstNode->uiKey, pstNode->uiValue);
	}

	printf("+++++++\n");
	for (pstRbtNode = rb_first(&stRbtRoot); pstRbtNode; pstRbtNode = rb_next(pstRbtNode)) 
	{		
		pstNode = rb_entry(pstRbtNode, DBG_RBT_NODE_S, stNode);
		printf("RBT_SCAN: <%u/%u>\n", pstNode->uiKey, pstNode->uiValue);
	}
	
	printf("+++++++\n");
	for (uiIndex = 1000; uiIndex >= 980; uiIndex--)
	{
		pstNode = (DBG_RBT_NODE_S *)malloc(sizeof(DBG_RBT_NODE_S));
		pstNode->uiKey = uiIndex;
		pstNode->uiValue = pstNode->uiKey*MULTI_CNT;
		rb_add(&(pstNode->stNode), &stRbtRoot, RbtCompare);
		printf("RBT_INSERT: <%u/%u>\n", pstNode->uiKey, pstNode->uiValue);
	}

	printf("+++++++\n");
	for (pstRbtNode = rb_first(&stRbtRoot); pstRbtNode; pstRbtNode = rb_next(pstRbtNode)) 
	{		
		pstNode = rb_entry(pstRbtNode, DBG_RBT_NODE_S, stNode);
		printf("RBT_SCAN: <%u/%u>\n", pstNode->uiKey, pstNode->uiValue);
	}

	printf("+++++++\n");
	for (uiIndex = 1; uiIndex <= 10; uiIndex++)
	{
		DBG_RBT_NODE_S stTestNode;
		stTestNode.uiKey = uiIndex;
		stTestNode.uiValue = stTestNode.uiKey*MULTI_CNT;
		pstRbtNode = rb_find(&(stTestNode.stNode), &stRbtRoot, RbtCompare);
		if (NULL != pstRbtNode)
		{
			rb_erase(pstRbtNode, &stRbtRoot);
			pstNode = rb_entry(pstRbtNode, DBG_RBT_NODE_S, stNode);
			printf("RBT_DELETE: <%u/%u>\n", stTestNode.uiKey, stTestNode.uiValue);
			free(pstNode);
		}		
	}
	
	printf("+++++++\n");
	for (pstRbtNode = rb_first(&stRbtRoot); pstRbtNode; pstRbtNode = rb_next(pstRbtNode)) 
	{		
		pstNode = rb_entry(pstRbtNode, DBG_RBT_NODE_S, stNode);
		printf("RBT_SCAN: <%u/%u>\n", pstNode->uiKey, pstNode->uiValue);
	}

	printf("+++++++\n");
	for (uiIndex = 1000; uiIndex >= 980; uiIndex--)
	{
		DBG_RBT_NODE_S stTestNode;
		stTestNode.uiKey = uiIndex;
		stTestNode.uiValue = stTestNode.uiKey*MULTI_CNT;
		pstRbtNode = rb_find(&(stTestNode.stNode), &stRbtRoot, RbtCompare);
		if (NULL != pstRbtNode)
		{
			rb_erase(pstRbtNode, &stRbtRoot);
			pstNode = rb_entry(pstRbtNode, DBG_RBT_NODE_S, stNode);
			printf("RBT_DELETE: <%u/%u>\n", stTestNode.uiKey, stTestNode.uiValue);
			free(pstNode);
		}	
	}
	
	printf("------\n");
	for (pstRbtNode = rb_first(&stRbtRoot); pstRbtNode; pstRbtNode = rb_next(pstRbtNode)) 
	{		
		pstNode = rb_entry(pstRbtNode, DBG_RBT_NODE_S, stNode);
		printf("RBT_SCAN: <%u/%u>\n", pstNode->uiKey, pstNode->uiValue);
	}
	printf("+++++++\n");

	int i;
	unsigned int uiCount = 0;
	for (i=1; i<100; i++)
	{
		TEST_START();

		TEST_PRINT_OUT("CIRCLE_CNT: %u", i);
		
		tStart = GET_MicroSec();
		uiCount = 0;
		for (uiIndex = 1; uiIndex <= 100000; uiIndex++)
		{
			pstNode = (DBG_RBT_NODE_S *)malloc(sizeof(DBG_RBT_NODE_S));
			pstNode->uiKey = uiIndex;
			pstNode->uiValue = pstNode->uiKey*MULTI_CNT;
			rb_add(&(pstNode->stNode), &stRbtRoot, RbtCompare);
			uiCount++;
			//TEST_PRINT_OUT("RBT_INSERT: <%u/%u>", pstNode->uiKey, pstNode->uiValue);
		}
		TEST_PRINT_OUT("RBT_INSERT: %u, cost %llu ms", uiCount, GET_MicroSec()-tStart);

		tStart = GET_MicroSec();
		uiCount = 0;
		for (pstRbtNode = rb_first(&stRbtRoot); pstRbtNode; pstRbtNode = rb_next(pstRbtNode)) 
		{
			pstNode = rb_entry(pstRbtNode, DBG_RBT_NODE_S, stNode);
			//TEST_PRINT_OUT("RBT_SCAN: <%u/%u>", pstNode->uiKey, pstNode->uiValue);
			uiCount++;
		}
		TEST_PRINT_OUT("RBT_COUNT(rb_destory before): %u, cost %llu ms", uiCount, GET_MicroSec()-tStart);
		TEST_CHECK_INT("RBT_CHECK 100000", MULTI_CNT*100000, RBT_FindInt(&stRbtRoot, 100000));

		tStart = GET_MicroSec();
		rb_destory(&stRbtRoot, RbtNodeFree);
		TEST_PRINT_OUT("RBT_COUNT(rb_destory): %u, cost %llu ms", uiCount, GET_MicroSec()-tStart);
		TEST_CHECK_INT("RBT_CHECK 100000", 0, RBT_FindInt(&stRbtRoot, 100000));

		tStart = GET_MicroSec();
		uiCount = 0;
		for (pstRbtNode = rb_first(&stRbtRoot); pstRbtNode; pstRbtNode = rb_next(pstRbtNode)) 
		{
			pstNode = rb_entry(pstRbtNode, DBG_RBT_NODE_S, stNode);
			//printf("RBT_SCAN: <%u/%u>\n", pstNode->uiKey, pstNode->uiValue);
			uiCount++;
		}
		TEST_PRINT_OUT("RBT_COUNT(rb_destory after): %u, cost %llu ms", uiCount, GET_MicroSec()-tStart);

		TEST_END();	
		sleep(1);
	}
}
*/

void DBG_CUT_IPV4_Point()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
    }
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    SWIFT_BUILD();

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void DBG_CUT_IPV4_Range_All()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START, IPV4_START+iIndex);
    }
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    RULE_SAVE_DEFAULT();

    SWIFT_BUILD();

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void DBG_CUT_IPV4_Range_Part()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex+5);
    }
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    SWIFT_BUILD();

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void DBG_CUT_IPV4_Range_Any()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    unsigned int TEST_RULE_ANY = 6;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex <= TEST_RULE_ANY)
        {
            RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START, IPV4_START+iIndex);
        }
    }
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    SWIFT_BUILD();

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void DBG_CUT_IPV4_Range_All_Reverse()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START, IPV4_START+(TEST_RULE_CNT-iIndex));
    }
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    SWIFT_BUILD();

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void DBG_CUT_IPV4_Range_Part_Reverse()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+(TEST_RULE_CNT-iIndex), IPV4_START+(TEST_RULE_CNT-iIndex)+5);
    }
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    SWIFT_BUILD();

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void DBG_CUT_IPV4_Range_Part_Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex+5);
    }
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %d count cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void DBG_CUT_IPV4_Range_Part_MemoryLeak()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned int uiIndex;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex+5);
    }
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

	for (uiIndex = 1; uiIndex <= 100; uiIndex++)
	{
	    tStart = GET_MicroSec();
	    TEST_PRINT_OUT("!SWIFT_BUILD cnt=%u", uiIndex);
	    SWIFT_BUILD();
	    TEST_PRINT_OUT("!SWIFT_BUILD %d count cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
	    SWIFT_DESTROY();
	    sleep(3);
	}
	
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

/*
void *thread_command_obj1_modify(void *arg)
{
    unsigned long long tStart = GET_MicroSec();
    unsigned int TEST_SPEED = 0;

	SET_RUN_CPU(0);
    while (1)
    {
    	if (g_uiThreadFlag)
    	{
    		break;
    	}

        sleep(3);
        tStart = GET_MicroSec();
        RULE_DEL("test100000");
        TEST_SPEED++;
        SWIFT_BUILD();
        TEST_PRINT_OUT("![MODIFY_DEL][SWIFT_BUILD] %u cost %llu ms", TEST_SPEED, GET_MicroSec()-tStart);

        sleep(3);
        tStart = GET_MicroSec();
        RULE_ADD("test100000");
        RULE_APPEND_OBJ("test100000", OBJECT_1, 100000);
        TEST_SPEED++;
        SWIFT_BUILD();
        TEST_PRINT_OUT("![MODIFY_ADD][SWIFT_BUILD] %u cost %llu ms", TEST_SPEED, GET_MicroSec()-tStart);
    }

    RULE_DEL_ALL(); 

    return NULL;
}

void TEST_QUICK_Build_Commit()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT  = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

	sleep(3);
	TEST_CHECK_INT("START BUILD", TEST_RULE_CNT, RULE_COUNT());
    for (iIndex = 1; iIndex <= 30; iIndex++)
    {
        sleep(1);
        tStart = GET_MicroSec();
        SWIFT_BUILD();
        TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
        TEST_CHECK_INT("BUILD_COMMIT_TIME", 1, ((GET_MicroSec()-tStart)<=5000));
    }

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();
    
    TEST_END();
}

void TEST_QUICK_Match_Obj_Any()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 50000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)",
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    TEST_CHECK_OBJ_QUICK_MATCH("[SWIFT_MATCH] obj1", OBJECT_1, 1, "test1");
    TEST_CHECK_OBJ_QUICK_MATCH("[SWIFT_MATCH] obj8", OBJECT_1, 8, "test8");
    TEST_CHECK_OBJ_QUICK_MATCH("[SWIFT_MATCH] obj888", OBJECT_1, 888, "test888");
    TEST_CHECK_OBJ_QUICK_MATCH("[SWIFT_MATCH] obj50000", OBJECT_1, 50000, "test50000");
    TEST_CHECK_OBJ_QUICK_MATCH("[SWIFT_MATCH] obj88888", OBJECT_1, 88888, "test50000");
    TEST_CHECK_OBJ_QUICK_MATCH("[SWIFT_MATCH] obj200000", OBJECT_1, 200000, "test50000");

    tStart = GET_MicroSec();
	unsigned int MATCH_CNT = TEST_RULE_CNT*200;
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        QUICK_MATCH_OBJ(OBJECT_1, (TEST_RULE_CNT-iIndex));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] %d count cost %llu ms (rate=%u/s)",
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_QUICK_Match_Obj_NoModify()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stMatchRet;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
    	MATCH_CNT++;
        stMatchRet = QUICK_MATCH_OBJ(OBJECT_1, 100000);
        if (STRING_Equal("test100000", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }   
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_QUICK_Match_Obj_NotFound()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stMatchRet;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)",
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
    	MATCH_CNT++;
        stMatchRet = QUICK_MATCH_OBJ(OBJECT_1, 2*100000);
        if (STRING_Equal("", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }  
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_QUICK_Match_Obj_Modify()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stMatchRet;
    pthread_t myCmd;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)",
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    g_uiThreadFlag = 0;
    pthread_create(&myCmd, NULL, thread_command_obj1_modify, NULL);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
    	MATCH_CNT++;
        stMatchRet = QUICK_MATCH_OBJ(OBJECT_1, 100000);
        if (STRING_Equal("test100000", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }    
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
	g_uiThreadFlag = 1;
	
	TEST_PRINT_OUT("+++thread WAIT..."); 
    pthread_join(myCmd, NULL);
    TEST_PRINT_OUT("+++thread OVER!"); 
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_QUICK_Match_Obj_ModifySpeed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    pthread_t myCmd;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    g_uiThreadFlag = 0;
    pthread_create(&myCmd, NULL, thread_command_obj1_modify, NULL);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
        QUICK_MATCH_OBJ(OBJECT_1, 100000);
        MATCH_CNT++;
        if (GET_MicroSec()-tPrint >= 1000)
        {
            tPrint = GET_MicroSec();
            TEST_COUNT++;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }    
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
	g_uiThreadFlag = 1;
	
	TEST_PRINT_OUT("+++thread WAIT..."); 
    pthread_join(myCmd, NULL);
    TEST_PRINT_OUT("+++thread OVER!"); 
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}
*/

void *thread_command_ipv4_modify(void *arg)
{
    unsigned long long tStart = GET_MicroSec();
    unsigned int TEST_SPEED = 0;
    unsigned int TEST_RULE_CNT = 100000;

	SET_RUN_CPU(0);
    while (1)
    {
    	if (g_uiThreadFlag)
    	{
    		break;
    	}

        sleep(3);
        tStart = GET_MicroSec();
        RULE_DEL("test100000");
        TEST_SPEED++;
        SWIFT_BUILD();
        TEST_PRINT_OUT("![MODIFY_DEL][SWIFT_BUILD] %u cost %llu ms", TEST_SPEED, GET_MicroSec()-tStart);

        sleep(3);
        tStart = GET_MicroSec();
        RULE_ADD("test100000");
        RULE_APPEND_SRC_IPV4_RANGE("test100000", IPV4_START+TEST_RULE_CNT, IPV4_START+TEST_RULE_CNT);
        TEST_SPEED++;
        SWIFT_BUILD();
        TEST_PRINT_OUT("![MODIFY_ADD][SWIFT_BUILD] %u cost %llu ms", TEST_SPEED, GET_MicroSec()-tStart);
    }

    RULE_DEL_ALL(); 

    return NULL;
}

/*
void TEST_QUICK_Match_IPv4_Point()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10;
    unsigned int START_RULE_ANY = 90000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    TEST_CHECK_IPV4_QUICK_MATCH("[SWIFT_MATCH] ip1", IPV4_START+1, "test1");
    TEST_CHECK_IPV4_QUICK_MATCH("[SWIFT_MATCH] ip8", IPV4_START+8, "test8");
    TEST_CHECK_IPV4_QUICK_MATCH("[SWIFT_MATCH] ip10", IPV4_START+10, "test10");

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void DBG_BITMAP_GET_FIRST()
{
    TEST_START();
    TEST_CHECK_INT("BITMAP_FIRST", 0,  BITMAP_FIRST(0x00000000));
    TEST_CHECK_INT("BITMAP_FIRST", 1,  BITMAP_FIRST(0xffffffff));
    TEST_CHECK_INT("BITMAP_FIRST", 2,  BITMAP_FIRST(0x7fffffff));
    TEST_CHECK_INT("BITMAP_FIRST", 3,  BITMAP_FIRST(0x3fffffff));
    TEST_CHECK_INT("BITMAP_FIRST", 4,  BITMAP_FIRST(0x1fffffff));
    TEST_CHECK_INT("BITMAP_FIRST", 5,  BITMAP_FIRST(0x0fffffff));
    TEST_CHECK_INT("BITMAP_FIRST", 6,  BITMAP_FIRST(0x07ffffff));
    TEST_CHECK_INT("BITMAP_FIRST", 7,  BITMAP_FIRST(0x03ffffff));
    TEST_CHECK_INT("BITMAP_FIRST", 8,  BITMAP_FIRST(0x01ffffff));
    TEST_CHECK_INT("BITMAP_FIRST", 9,  BITMAP_FIRST(0x00ffffff));
    TEST_CHECK_INT("BITMAP_FIRST", 10, BITMAP_FIRST(0x007fffff));
    TEST_CHECK_INT("BITMAP_FIRST", 11, BITMAP_FIRST(0x003fffff));
    TEST_CHECK_INT("BITMAP_FIRST", 12, BITMAP_FIRST(0x001fffff));
    TEST_CHECK_INT("BITMAP_FIRST", 13, BITMAP_FIRST(0x000fffff));
    TEST_CHECK_INT("BITMAP_FIRST", 14, BITMAP_FIRST(0x0007ffff));
    TEST_CHECK_INT("BITMAP_FIRST", 15, BITMAP_FIRST(0x0003ffff));
    TEST_CHECK_INT("BITMAP_FIRST", 16, BITMAP_FIRST(0x0001ffff));
    TEST_CHECK_INT("BITMAP_FIRST", 17, BITMAP_FIRST(0x0000ffff));
    TEST_CHECK_INT("BITMAP_FIRST", 18, BITMAP_FIRST(0x00007fff));
    TEST_CHECK_INT("BITMAP_FIRST", 19, BITMAP_FIRST(0x00003fff));
    TEST_CHECK_INT("BITMAP_FIRST", 20, BITMAP_FIRST(0x00001fff));
    TEST_CHECK_INT("BITMAP_FIRST", 21, BITMAP_FIRST(0x00000fff));
    TEST_CHECK_INT("BITMAP_FIRST", 22, BITMAP_FIRST(0x000007ff));
    TEST_CHECK_INT("BITMAP_FIRST", 23, BITMAP_FIRST(0x000003ff));
    TEST_CHECK_INT("BITMAP_FIRST", 24, BITMAP_FIRST(0x000001ff));
    TEST_CHECK_INT("BITMAP_FIRST", 25, BITMAP_FIRST(0x000000ff));
    TEST_CHECK_INT("BITMAP_FIRST", 26, BITMAP_FIRST(0x0000007f));
    TEST_CHECK_INT("BITMAP_FIRST", 27, BITMAP_FIRST(0x0000003f));
    TEST_CHECK_INT("BITMAP_FIRST", 28, BITMAP_FIRST(0x0000001f));
    TEST_CHECK_INT("BITMAP_FIRST", 29, BITMAP_FIRST(0x0000000f));
    TEST_CHECK_INT("BITMAP_FIRST", 30, BITMAP_FIRST(0x00000007));
    TEST_CHECK_INT("BITMAP_FIRST", 31, BITMAP_FIRST(0x00000003));
    TEST_CHECK_INT("BITMAP_FIRST", 32, BITMAP_FIRST(0x00000001));
    TEST_END();
}

void TEST_BITMAP_Match_Obj_Any()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 50000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)",
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    TEST_CHECK_OBJ_QUICK_MATCH_BITMAP("[SWIFT_MATCH] obj1", OBJECT_1, 1, "test1");
    TEST_CHECK_OBJ_QUICK_MATCH_BITMAP("[SWIFT_MATCH] obj8", OBJECT_1, 8, "test8");
    TEST_CHECK_OBJ_QUICK_MATCH_BITMAP("[SWIFT_MATCH] obj888", OBJECT_1, 888, "test888");
    TEST_CHECK_OBJ_QUICK_MATCH_BITMAP("[SWIFT_MATCH] obj88888", OBJECT_1, 88888, "test50000");
    TEST_CHECK_OBJ_QUICK_MATCH_BITMAP("[SWIFT_MATCH] obj200000", OBJECT_1, 200000, "test50000");

    tStart = GET_MicroSec();
	unsigned int MATCH_CNT = TEST_RULE_CNT*200;
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        QUICK_MATCH_BITMAP_OBJ(OBJECT_1, (TEST_RULE_CNT-iIndex));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] %d count cost %llu ms (rate=%u/s)",
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_Obj_NoModify()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stMatchRet;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
    	MATCH_CNT++;
        stMatchRet = QUICK_MATCH_BITMAP_OBJ(OBJECT_1, 100000);
        if (STRING_Equal("test100000", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }   
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_Obj_NotFound()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stMatchRet;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)",
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
    	MATCH_CNT++;
        stMatchRet = QUICK_MATCH_BITMAP_OBJ(OBJECT_1, 2*100000);
        if (STRING_Equal("", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }  
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_Obj_Modify()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    pthread_t myCmd;
    RULE_SUMMARY_S stMatchRet;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)",
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    g_uiThreadFlag = 0;
    pthread_create(&myCmd, NULL, thread_command_obj1_modify, NULL);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
    	MATCH_CNT++;
        stMatchRet = QUICK_MATCH_BITMAP_OBJ(OBJECT_1, 100000);
        if (STRING_Equal("test100000", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }    
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
	g_uiThreadFlag = 1;
	
	TEST_PRINT_OUT("+++thread WAIT..."); 
    pthread_join(myCmd, NULL);
    TEST_PRINT_OUT("+++thread OVER!"); 
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_Obj_ModifySpeed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    pthread_t myCmd;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    g_uiThreadFlag = 0;
    pthread_create(&myCmd, NULL, thread_command_obj1_modify, NULL);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
        QUICK_MATCH_BITMAP_OBJ(OBJECT_1, 100000);
        MATCH_CNT++;
        if (GET_MicroSec()-tPrint >= 1000)
        {
            tPrint = GET_MicroSec();
            TEST_COUNT++;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }    
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
	g_uiThreadFlag = 1;
	
	TEST_PRINT_OUT("+++thread WAIT..."); 
    pthread_join(myCmd, NULL);
    TEST_PRINT_OUT("+++thread OVER!"); 
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}
*/

void TEST_BITMAP_Match_SrcIPv4_Point()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100;
    unsigned int START_RULE_ANY = 90;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    for (iIndex = 1; iIndex < START_RULE_ANY; iIndex++)
    {
        char szTag[256] = {0};
        char szResult[256] = {0};
        sprintf(szTag, "[SWIFT_MATCH] ip%u", iIndex);
        sprintf(szResult, "test%u", iIndex);
        CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP(szTag, IPV4_START+iIndex, szResult);
    }
    for (iIndex = START_RULE_ANY; iIndex < TEST_RULE_CNT; iIndex++)
    {
        char szTag[256] = {0};
        char szResult[256] = {0};
        sprintf(szTag, "[SWIFT_MATCH] ip%u", iIndex);
        sprintf(szResult, "test%u", START_RULE_ANY);
        CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP(szTag, IPV4_START+iIndex, szResult);
    }
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_SrcIPv4_Range()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100;
    unsigned int START_RULE_ANY = 90;
    unsigned int TEST_RANGE = 5;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex+TEST_RANGE);
        }
    }
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    RULE_SAVE_DEFAULT();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip1", IPV4_START+1, "test1");
    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip8", IPV4_START+8, "test3");
    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip88", IPV4_START+88, "test83");
    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip100", IPV4_START+100, "test90");
    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip200", IPV4_START+200, "test90");

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_SrcIPv4_Any()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 90000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip1", IPV4_START+1, "test1");
    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip8", IPV4_START+8, "test8");
    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip888", IPV4_START+888, "test888");
    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip88888", IPV4_START+88888, "test88888");
    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip200000", IPV4_START+200000, "test90000");

    tStart = GET_MicroSec();
	unsigned int MATCH_CNT = TEST_RULE_CNT*500;
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        SWIFT_MATCH_SRC_IPV4(IPV4_START+(TEST_RULE_CNT-iIndex));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_SrcIPv4_NoModify()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stMatchRet;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
        MATCH_CNT++;
        stMatchRet = SWIFT_MATCH_SRC_IPV4(IPV4_START+100000);
        if (STRING_Equal("test100000", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }    
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_SrcIPv4_NotFound()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stMatchRet;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip200000", (IPV4_START+2*100000), "");

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
        MATCH_CNT++;
        stMatchRet = SWIFT_MATCH_SRC_IPV4(IPV4_START+2*100000);
        if (!STRING_Equal("test100000", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    } 
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_SrcIPv4_Modify()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    pthread_t myCmd;
    RULE_SUMMARY_S stMatchRet;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    g_uiThreadFlag = 0;
    pthread_create(&myCmd, NULL, thread_command_ipv4_modify, NULL);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
        MATCH_CNT++;
        stMatchRet = SWIFT_MATCH_SRC_IPV4(IPV4_START+100000);
        if (STRING_Equal("test100000", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }   
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
	g_uiThreadFlag = 1;
	
	TEST_PRINT_OUT("+++thread WAIT..."); 
    pthread_join(myCmd, NULL);
    TEST_PRINT_OUT("+++thread OVER!"); 
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_SrcIPv4_ModifySpeed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    pthread_t myCmd;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    g_uiThreadFlag = 0;
    pthread_create(&myCmd, NULL, thread_command_ipv4_modify, NULL);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
        MATCH_CNT++;
    	SWIFT_MATCH_SRC_IPV4(IPV4_START+100000);
        if (GET_MicroSec()-tPrint >= 1000)
        {
            tPrint = GET_MicroSec();
            TEST_COUNT++;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
	g_uiThreadFlag = 1;
	
	TEST_PRINT_OUT("+++thread WAIT..."); 
    pthread_join(myCmd, NULL);
    TEST_PRINT_OUT("+++thread OVER!"); 
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_DestIPv4_Any()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 90000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    CHECK_DEST_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip1", IPV4_START+1, "test1");
    CHECK_DEST_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip8", IPV4_START+8, "test8");
    CHECK_DEST_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip888", IPV4_START+888, "test888");
    CHECK_DEST_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip88888", IPV4_START+88888, "test88888");
    CHECK_DEST_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip200000", IPV4_START+200000, "test90000");

    tStart = GET_MicroSec();
	unsigned int MATCH_CNT = TEST_RULE_CNT*500;
    for (iIndex = 1; iIndex <= MATCH_CNT; iIndex++)
    {
        SWIFT_MATCH_DEST_IPV4(IPV4_START+(TEST_RULE_CNT-iIndex));
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_DestIPv4_NoModify()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stMatchRet;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
        MATCH_CNT++;
        stMatchRet = SWIFT_MATCH_DEST_IPV4(IPV4_START+100000);
        if (STRING_Equal("test100000", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }    
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_DestIPv4_NotFound()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stMatchRet;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    CHECK_SRC_IPV4_SWIFT_MATCH_BITMAP("[SWIFT_MATCH] ip200000", (IPV4_START+2*100000), "");

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
        MATCH_CNT++;
        stMatchRet = SWIFT_MATCH_DEST_IPV4(IPV4_START+2*100000);
        if (!STRING_Equal("test100000", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    } 
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_DestIPv4_Modify()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    pthread_t myCmd;
    RULE_SUMMARY_S stMatchRet;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    g_uiThreadFlag = 0;
    pthread_create(&myCmd, NULL, thread_command_ipv4_modify, NULL);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
        MATCH_CNT++;
        stMatchRet = SWIFT_MATCH_DEST_IPV4(IPV4_START+100000);
        if (STRING_Equal("test100000", stMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
        if (GET_MicroSec()-tPrint >= 1000)
        {
            TEST_COUNT++;
            TEST_PRINT_OUT("![SWIFT_MATCH] %u/%u cost %llu ms", MATCH_SUCC, MATCH_FAIL, GET_MicroSec()-tPrint);
            tPrint = GET_MicroSec();
            MATCH_SUCC = 0;
            MATCH_FAIL = 0;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }   
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
	g_uiThreadFlag = 1;
	
	TEST_PRINT_OUT("+++thread WAIT..."); 
    pthread_join(myCmd, NULL);
    TEST_PRINT_OUT("+++thread OVER!"); 
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_BITMAP_Match_DestIPv4_ModifySpeed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    pthread_t myCmd;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100000;
    unsigned int START_RULE_ANY = 100001;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    g_uiThreadFlag = 0;
    pthread_create(&myCmd, NULL, thread_command_ipv4_modify, NULL);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
        MATCH_CNT++;
    	SWIFT_MATCH_DEST_IPV4(IPV4_START+100000);
        if (GET_MicroSec()-tPrint >= 1000)
        {
            tPrint = GET_MicroSec();
            TEST_COUNT++;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
	g_uiThreadFlag = 1;
	
	TEST_PRINT_OUT("+++thread WAIT..."); 
    pthread_join(myCmd, NULL);
    TEST_PRINT_OUT("+++thread OVER!"); 
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

/*
void TEST_Random_Quick_Match_Obj()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stSlowMatchRet;
    RULE_SUMMARY_S stFastMatchRet;
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        int i;
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        for (i=1; i<=ITEM_COUNT_PER_RULE; i++)
        {
            unsigned int uiObj = rand()%TEST_RULE_CNT;
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, uiObj);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    tStart = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        unsigned int uiObj = rand()%(2*TEST_RULE_CNT);
        
        MATCH_CNT++;
        stSlowMatchRet = MATCH_FIRST_RULE_BY_OBJ(OBJECT_1, uiObj);
        stFastMatchRet = QUICK_MATCH_OBJ(OBJECT_1, uiObj);
        if (STRING_Equal(stSlowMatchRet.szRuleName, stFastMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_Random_Bitmap_Match_Obj()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stSlowMatchRet;
    RULE_SUMMARY_S stFastMatchRet;
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        int i;
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        for (i=1; i<=ITEM_COUNT_PER_RULE; i++)
        {
            unsigned int uiObj = rand()%TEST_RULE_CNT;
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, uiObj);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    tStart = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        unsigned int uiObj = rand()%(2*TEST_RULE_CNT);
        
        MATCH_CNT++;
        stSlowMatchRet = MATCH_FIRST_RULE_BY_OBJ(OBJECT_1, uiObj);
        stFastMatchRet = QUICK_MATCH_BITMAP_OBJ(OBJECT_1, uiObj);
        if (STRING_Equal(stSlowMatchRet.szRuleName, stFastMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}
*/

void TEST_Random_Bitmap_Match_SrcIPv4()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stSlowMatchRet;
    RULE_SUMMARY_S stFastMatchRet;
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        int i;
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        for (i=1; i<=ITEM_COUNT_PER_RULE; i++)
        {
            unsigned int uiObj = rand()%TEST_RULE_CNT;
            RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+uiObj, IPV4_START+uiObj+10);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    tStart = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        unsigned int uiObj = rand()%(2*TEST_RULE_CNT);
        
        MATCH_CNT++;        
        stSlowMatchRet = MATCH_FIRST_RULE_BY_SRC_IPV4(IPV4_START+uiObj);
        stFastMatchRet = SWIFT_MATCH_SRC_IPV4(IPV4_START+uiObj);
        if (STRING_Equal(stSlowMatchRet.szRuleName, stFastMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_Random_Bitmap_Match_DestIPv4()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    RULE_SUMMARY_S stSlowMatchRet;
    RULE_SUMMARY_S stFastMatchRet;
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        int i;
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        for (i=1; i<=ITEM_COUNT_PER_RULE; i++)
        {
            unsigned int uiObj = rand()%TEST_RULE_CNT;
            RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+uiObj, IPV4_START+uiObj+10);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    tStart = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int MATCH_FAIL = 0;
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        unsigned int uiObj = rand()%(2*TEST_RULE_CNT);
        
        MATCH_CNT++;        
        stSlowMatchRet = MATCH_FIRST_RULE_BY_DEST_IPV4(IPV4_START+uiObj);
        stFastMatchRet = SWIFT_MATCH_DEST_IPV4(IPV4_START+uiObj);
        if (STRING_Equal(stSlowMatchRet.szRuleName, stFastMatchRet.szRuleName))
        {
            MATCH_SUCC++;
        }
        else
        {
            MATCH_FAIL++;
        }
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

/*
void TEST_Random_Quick_Match_Obj_Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        int i;
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        for (i=1; i<=ITEM_COUNT_PER_RULE; i++)
        {
            unsigned int uiObj = rand()%TEST_RULE_CNT;
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, uiObj);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int TEST_COUNT = 0;

    unsigned int uiObj = rand()%(TEST_RULE_CNT+100);
    while (1)
    {
        MATCH_CNT++;
        QUICK_MATCH_OBJ(OBJECT_1, uiObj);
        MATCH_SUCC++;
        if (GET_MicroSec()-tPrint >= 1000)
        {
            uiObj = rand()%(TEST_RULE_CNT+100);
            tPrint = GET_MicroSec();
            TEST_COUNT++;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_Random_Bitmap_Match_Obj_Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        int i;
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        for (i=1; i<=ITEM_COUNT_PER_RULE; i++)
        {
            unsigned int uiObj = rand()%TEST_RULE_CNT;
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, uiObj);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    
    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;
    unsigned int TEST_COUNT = 0;
    unsigned int uiObj = rand()%(TEST_RULE_CNT+100);
    while (1)
    {
        MATCH_CNT++;
        QUICK_MATCH_BITMAP_OBJ(OBJECT_1, uiObj);
        MATCH_SUCC++;
        if (GET_MicroSec()-tPrint >= 1000)
        {
            uiObj = rand()%(TEST_RULE_CNT+100);
            tPrint = GET_MicroSec();
            TEST_COUNT++;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}
*/

void TEST_Random_Bitmap_Match_SrcIPv4_Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        int i;
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        for (i=1; i<=ITEM_COUNT_PER_RULE; i++)
        {
            unsigned int uiObj = rand()%TEST_RULE_CNT;
            RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+uiObj, IPV4_START+uiObj+100);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    
    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;

    unsigned int TEST_COUNT = 0;
    unsigned int uiObj = rand()%(TEST_RULE_CNT+100);
    while (1)
    {
        MATCH_CNT++;
        SWIFT_MATCH_SRC_IPV4(IPV4_START+uiObj);
        MATCH_SUCC++;
        if (GET_MicroSec()-tPrint >= 1000)
        {
            uiObj = rand()%(TEST_RULE_CNT+100);
            tPrint = GET_MicroSec();
            TEST_COUNT++;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_Random_Bitmap_Match_DestIPv4_Speed()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 10000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        int i;
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        for (i=1; i<=ITEM_COUNT_PER_RULE; i++)
        {
            unsigned int uiObj = rand()%TEST_RULE_CNT;
            RULE_APPEND_DEST_IPV4_RANGE(szRuleName, IPV4_START+uiObj, IPV4_START+uiObj+100);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    
    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int MATCH_SUCC = 0;

    unsigned int TEST_COUNT = 0;
    unsigned int uiObj = rand()%(TEST_RULE_CNT+100);
    while (1)
    {
        MATCH_CNT++;
        SWIFT_MATCH_DEST_IPV4(IPV4_START+uiObj);
        MATCH_SUCC++;
        if (GET_MicroSec()-tPrint >= 1000)
        {
            uiObj = rand()%(TEST_RULE_CNT+100);
            tPrint = GET_MicroSec();
            TEST_COUNT++;
            if (TEST_COUNT >= 20)
            {
                break;
            }
        }
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void *thread_memory_state(void *arg)
{
    unsigned int uiWaitSec;
        
	SET_RUN_CPU(0);
    while (1)
    {
    	if (g_uiThreadFlag)
    	{
    		break;
    	}

        uiWaitSec = rand()%13;
        sleep(uiWaitSec);
        SET_VALGRIND_DEBUG(1);
        TEST_PRINT_OUT("![MOMORY]STATE=1");

        uiWaitSec = rand()%13;
        sleep(uiWaitSec);
        SET_VALGRIND_DEBUG(0);
        TEST_PRINT_OUT("![MOMORY]STATE=0");
    }

    return NULL;
}

void TEST_SWIFT_Valgrind_MemoryLeak()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    pthread_t myCmd;
    unsigned long long tStart;
    unsigned long long tPrint;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 1000;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        int i;
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        for (i=1; i<=ITEM_COUNT_PER_RULE; i++)
        {
            RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex+100);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    g_uiThreadFlag = 0;
    pthread_create(&myCmd, NULL, thread_memory_state, NULL);

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);
    
    tStart = GET_MicroSec();
    tPrint = GET_MicroSec();
	unsigned int MATCH_CNT = 0;
    unsigned int TEST_COUNT = 0;
    while (1)
    {
        MATCH_CNT++;
        
        tStart = GET_MicroSec();
        RULE_DEL("test10000");
        SWIFT_BUILD();
        TEST_PRINT_OUT("![MODIFY_DEL][SWIFT_BUILD] %u cost %llu ms", MATCH_CNT, GET_MicroSec()-tStart);

        tStart = GET_MicroSec();
        RULE_ADD("test1000");
        RULE_APPEND_SRC_IPV4_RANGE("test1000", IPV4_START+1000, IPV4_START+1000+100);
        SWIFT_BUILD();
        TEST_PRINT_OUT("![MODIFY_ADD][SWIFT_BUILD] %u cost %llu ms", MATCH_CNT, GET_MicroSec()-tStart);
        SWIFT_DESTROY();
        sleep(1);
        if (GET_MicroSec()-tPrint >= 1000)
        {
            tPrint = GET_MicroSec();
            TEST_COUNT++;
            if (TEST_COUNT >= 1000)
            {
                break;
            }
        }
    }
    tDiff = GET_MicroSec()-tStart;
	TEST_PRINT_OUT("![SWIFT_MATCH] END %d count cost %llu ms (rate=%u/s)", 
    				MATCH_CNT, tDiff, GET_Rate(MATCH_CNT, tDiff));
    g_uiThreadFlag = 1;
    
    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

/*
void TEST_FORMAL_QUICK_Match_Obj_Point()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    PACKET_INFO_S stMatchInfo;
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100;
    unsigned int START_RULE_ANY = 50;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    stMatchInfo.uiKeyMask = RULE_KEY_OBJ_1;
    
    stMatchInfo.auiObject[OBJECT_1] = 1;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj1", stMatchInfo, "test1");

    stMatchInfo.auiObject[OBJECT_1] = 2;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj2", stMatchInfo, "test2");

    stMatchInfo.auiObject[OBJECT_1] = 8;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj8", stMatchInfo, "test8");
    
    stMatchInfo.auiObject[OBJECT_1] = 31;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj31", stMatchInfo, "test31");

    stMatchInfo.auiObject[OBJECT_1] = 32;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj32", stMatchInfo, "test32");

    stMatchInfo.auiObject[OBJECT_1] = 33;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj33", stMatchInfo, "test33");

    stMatchInfo.auiObject[OBJECT_1] = 49;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj49", stMatchInfo, "test49");

    stMatchInfo.auiObject[OBJECT_1] = 50;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj50", stMatchInfo, "test50");

    stMatchInfo.auiObject[OBJECT_1] = 51;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj51", stMatchInfo, "test50");

    stMatchInfo.auiObject[OBJECT_1] = 100;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj100", stMatchInfo, "test50");

    stMatchInfo.auiObject[OBJECT_1] = 10000;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj10000", stMatchInfo, "test50");

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_FORMAL_QUICK_Match_IPv4_Point()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    PACKET_INFO_S stMatchInfo;
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 20;
    unsigned int START_RULE_ANY = 10;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
        	RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

    stMatchInfo.uiKeyMask = RULE_KEY_SIP;
    
    stMatchInfo.stPacket.ipSrc = IPV4_START+1;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] ip1", stMatchInfo, "test1");

    stMatchInfo.stPacket.ipSrc = IPV4_START+8;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] ip8", stMatchInfo, "test8");

    stMatchInfo.stPacket.ipSrc = IPV4_START+10;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] ip10", stMatchInfo, "test10");

    stMatchInfo.stPacket.ipSrc = IPV4_START+11;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] ip11", stMatchInfo, "test10");

    stMatchInfo.stPacket.ipSrc = IPV4_START+20;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] ip20", stMatchInfo, "test10");

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}

void TEST_FORMAL_QUICK_Match_Obj_IPv4()
{
    unsigned int iIndex = 0;
    char szRuleName[100];
    PACKET_INFO_S stMatchInfo;
    unsigned long long tStart;
    unsigned long long tDiff;

    TEST_START();

    unsigned int TEST_RULE_CNT = 100;
    unsigned int START_RULE_ANY = 50;
    tStart = GET_MicroSec();
    for (iIndex = 1; iIndex <= TEST_RULE_CNT; iIndex++)
    {
        sprintf(szRuleName, "test%d", iIndex);
        RULE_ADD(szRuleName);
        if (iIndex < START_RULE_ANY)
        {
            RULE_APPEND_OBJ(szRuleName, OBJECT_1, iIndex);
            RULE_APPEND_SRC_IPV4_RANGE(szRuleName, IPV4_START+iIndex, IPV4_START+iIndex);
        }
    }
    tDiff = GET_MicroSec()-tStart;
    TEST_PRINT_OUT("!RULE_ADD %d count cost %llu ms (rate=%u/s)", 
    				TEST_RULE_CNT, tDiff, GET_Rate(TEST_RULE_CNT, tDiff));
    TEST_CHECK_INT("RULE_COUNT", TEST_RULE_CNT, RULE_COUNT());
    //RULE_PRINT_CFG();

    tStart = GET_MicroSec();
    SWIFT_BUILD();
    TEST_PRINT_OUT("!SWIFT_BUILD %u cost %llu ms", TEST_RULE_CNT, GET_MicroSec()-tStart);

#if 0
    stMatchInfo.uiKeyMask = RULE_KEY_OBJ_1|RULE_KEY_SIP;
    
    stMatchInfo.auiObject[OBJECT_1] = 1;
    stMatchInfo.stPacket.ipSrc = IPV4_START+1;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj1", stMatchInfo, "test1");

    stMatchInfo.auiObject[OBJECT_1] = 2;
    stMatchInfo.stPacket.ipSrc = IPV4_START+1;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj2", stMatchInfo, "test50");

    stMatchInfo.auiObject[OBJECT_1] = 8;
    stMatchInfo.stPacket.ipSrc = IPV4_START+8;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj8", stMatchInfo, "test8");
    
    stMatchInfo.auiObject[OBJECT_1] = 31;
    stMatchInfo.stPacket.ipSrc = IPV4_START+31;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj31", stMatchInfo, "test31");

    stMatchInfo.auiObject[OBJECT_1] = 32;
    stMatchInfo.stPacket.ipSrc = IPV4_START+32;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj32", stMatchInfo, "test32");

    stMatchInfo.auiObject[OBJECT_1] = 33;
    stMatchInfo.stPacket.ipSrc = IPV4_START+11;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj33", stMatchInfo, "test50");

    stMatchInfo.auiObject[OBJECT_1] = 49;
    stMatchInfo.stPacket.ipSrc = IPV4_START+49;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj49", stMatchInfo, "test49");

    stMatchInfo.auiObject[OBJECT_1] = 50;
    stMatchInfo.stPacket.ipSrc = IPV4_START+50;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj50", stMatchInfo, "test50");

    stMatchInfo.auiObject[OBJECT_1] = 51;
    stMatchInfo.stPacket.ipSrc = IPV4_START+50;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj51", stMatchInfo, "test50");

    stMatchInfo.auiObject[OBJECT_1] = 100;
    stMatchInfo.stPacket.ipSrc = IPV4_START+200;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj100", stMatchInfo, "test50");

    stMatchInfo.auiObject[OBJECT_1] = 10000;
    stMatchInfo.stPacket.ipSrc = IPV4_START+10000;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH] obj10000", stMatchInfo, "test50");
#endif

    stMatchInfo.uiKeyMask = RULE_KEY_OBJ_1|RULE_KEY_OBJ_2|RULE_KEY_SIP;
    
    RULE_APPEND_OBJ("test50", OBJECT_2, 50);
    SWIFT_BUILD();
    stMatchInfo.auiObject[OBJECT_1] = 1;
    stMatchInfo.auiObject[OBJECT_2] = 50;
    stMatchInfo.stPacket.ipSrc = IPV4_START+20000;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH-1] obj_1_50_20000", stMatchInfo, "test50");
    stMatchInfo.auiObject[OBJECT_1] = 1;
    stMatchInfo.auiObject[OBJECT_2] = 100;
    stMatchInfo.stPacket.ipSrc = IPV4_START+20000;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH-2] obj_1_100_20000", stMatchInfo, "test51");

    RULE_APPEND_OBJ("test51", OBJECT_2, 50);
    SWIFT_BUILD();
    stMatchInfo.auiObject[OBJECT_1] = 1;
    stMatchInfo.auiObject[OBJECT_2] = 100;
    stMatchInfo.stPacket.ipSrc = IPV4_START+30000;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH-3] obj_1_100_30000", stMatchInfo, "test52");

    RULE_APPEND_OBJ("test51", OBJECT_2, 100);
    SWIFT_BUILD();
    stMatchInfo.auiObject[OBJECT_1] = 1;
    stMatchInfo.auiObject[OBJECT_2] = 100;
    stMatchInfo.stPacket.ipSrc = IPV4_START+30000;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH-4] obj_1_100_30000", stMatchInfo, "test51");
    stMatchInfo.auiObject[OBJECT_1] = 1;
    stMatchInfo.auiObject[OBJECT_2] = 200;
    stMatchInfo.stPacket.ipSrc = IPV4_START+30000;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH-5] obj_1_200_30000", stMatchInfo, "test52");

    RULE_REMOVE_OBJ("test51", OBJECT_2, 100);
    SWIFT_BUILD();
    stMatchInfo.auiObject[OBJECT_1] = 1;
    stMatchInfo.auiObject[OBJECT_2] = 100;
    stMatchInfo.stPacket.ipSrc = IPV4_START+30000;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH-6] obj_1_100_30000", stMatchInfo, "test52");

    RULE_REMOVE_OBJ("test51", OBJECT_2, 50);
    SWIFT_BUILD();
    stMatchInfo.auiObject[OBJECT_1] = 1;
    stMatchInfo.auiObject[OBJECT_2] = 50;
    stMatchInfo.stPacket.ipSrc = IPV4_START+60000;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH-7] obj_1_50_60000", stMatchInfo, "test50");
    stMatchInfo.auiObject[OBJECT_1] = 1;
    stMatchInfo.auiObject[OBJECT_2] = 100;
    stMatchInfo.stPacket.ipSrc = IPV4_START+60000;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH-8] obj_1_100_60000", stMatchInfo, "test51");

    RULE_REMOVE_OBJ("test50", OBJECT_2, 50);
    SWIFT_BUILD();
    stMatchInfo.auiObject[OBJECT_1] = 1;
    stMatchInfo.auiObject[OBJECT_2] = 100;
    stMatchInfo.stPacket.ipSrc = IPV4_START+20000;
    TEST_CHECK_IPV4_FORMAL_QUICK_MATCH("[QUICK_FORMAL_MATCH-9] obj_1_50_20000", stMatchInfo, "test50");

    RULE_DEL_ALL();
    TEST_PRINT_OUT("RULE_DEL_ALL"); 
    TEST_CHECK_INT("RULE_COUNT", 0, RULE_COUNT());
    RULE_PRINT_CFG();

    TEST_END();
}
*/

int acl_tc()
{
	SET_RUN_CPU(1);
	
// CFG	
#if 0
    TEST_CFG_AddRule_Basic();                   // ok
    TEST_CFG_AddRule_Speed();                   // ok 
    TEST_CFG_DelRule_Basic();                   // ok
    TEST_CFG_DelRule_Speed();                   // ok
    TEST_CFG_DelRule_Speed_Reverse();           // ok
    //TEST_CFG_Append_Obj_Basic();
    //TEST_CFG_DelRule_WithObj_Speed();
    TEST_CFG_Append_SrcIPv4_Basic();            // ok
    TEST_CFG_Append_SrcIPv4_Basic_Range2();     // ok
    //TEST_CFG_SAVE_WithObject();
#endif

// MATCH_Normal_Obj
#if 0
    TEST_MATCH_Normal_Obj_Basic();
    TEST_MATCH_Normal_Obj_Any();
    TEST_MATCH_Normal_Obj_BestSpeed();
    TEST_MATCH_Normal_Obj_10Speed();
    TEST_MATCH_Normal_Obj_20Speed();	
    TEST_MATCH_Normal_Obj_50Speed();
    TEST_MATCH_Normal_Obj_100Speed();
    TEST_MATCH_Normal_Obj_1000Speed();
    TEST_MATCH_Normal_Obj_WorstSpeed();
#endif

// MATCH_Normal_SrcIPv4
#if 0
    TEST_MATCH_Normal_SrcIPv4_Basic();          // ok
    TEST_MATCH_Normal_SrcIPv4_Any();            // ok
    TEST_MATCH_Normal_SrcIPv4_BestSpeed();      // ok
    TEST_MATCH_Normal_SrcIPv4_10Speed();        // ok
    TEST_MATCH_Normal_SrcIPv4_20Speed();        // ok
    TEST_MATCH_Normal_SrcIPv4_50Speed();        // ok
    TEST_MATCH_Normal_SrcIPv4_100Speed();       // ok
    TEST_MATCH_Normal_SrcIPv4_1000Speed();      // ok
    TEST_MATCH_Normal_SrcIPv4_WorstSpeed();     // ok
#endif

// MATCH_Normal_DestIPv4
#if 0
    TEST_MATCH_Normal_DestIPv4_Basic();         // ok
    TEST_MATCH_Normal_DestIPv4_Any();           // ok
    TEST_MATCH_Normal_DestIPv4_BestSpeed();     // ok
    TEST_MATCH_Normal_DestIPv4_10Speed();       // ok
    TEST_MATCH_Normal_DestIPv4_20Speed();       // ok
    TEST_MATCH_Normal_DestIPv4_50Speed();       // ok
    TEST_MATCH_Normal_DestIPv4_100Speed();      // ok
    TEST_MATCH_Normal_DestIPv4_1000Speed();     // ok
    TEST_MATCH_Normal_DestIPv4_WorstSpeed();    // ok
#endif

// RBT
#if 0
    DBG_RBT_Operate();
#endif

// DEBUG
#if 0
    DBG_CUT_IPV4_Point();                       // ok
    DBG_CUT_IPV4_Range_All();                   // ok
    DBG_CUT_IPV4_Range_Part();                  // ok
    DBG_CUT_IPV4_Range_Any();                   // ok
    DBG_CUT_IPV4_Range_All_Reverse();           // ok
    DBG_CUT_IPV4_Range_Part_Reverse();          // ok
    DBG_CUT_IPV4_Range_Part_Speed();            // ok
    DBG_CUT_IPV4_Range_Part_MemoryLeak();       // ok
#endif

// BUILD
#if 0
    TEST_QUICK_Build_Commit();
#endif

// QUICK_Match_Obj
#if 0
    TEST_QUICK_Match_Obj_Any();
    TEST_QUICK_Match_Obj_NoModify();
    TEST_QUICK_Match_Obj_NotFound();
    TEST_QUICK_Match_Obj_Modify();
    TEST_QUICK_Match_Obj_ModifySpeed();
#endif

// QUICK_Match_IPv4
#if 0
	TEST_QUICK_Match_IPv4_Point();
    TEST_QUICK_Match_IPv4_Any();
    TEST_QUICK_Match_IPv4_NoModify();
    TEST_QUICK_Match_IPv4_NotFound();
    TEST_QUICK_Match_IPv4_Modify();
    TEST_QUICK_Match_IPv4_ModifySpeed();
#endif

// DBG_BITMAP
#if 0
    DBG_BITMAP_GET_FIRST();
#endif

// BITMAP_Match_Obj
    //TEST_BITMAP_Match_Obj_Any();//temp
#if 0
    TEST_BITMAP_Match_Obj_Any();
    TEST_BITMAP_Match_Obj_NoModify();
    TEST_BITMAP_Match_Obj_NotFound();
    TEST_BITMAP_Match_Obj_Modify();
    TEST_BITMAP_Match_Obj_ModifySpeed();
#endif

// BITMAP_Match_SrcIPv4
#if 0
    TEST_BITMAP_Match_SrcIPv4_Point();          //ok
    TEST_BITMAP_Match_SrcIPv4_Range();          //ok
    TEST_BITMAP_Match_SrcIPv4_Any();            //ok
    TEST_BITMAP_Match_SrcIPv4_NoModify();       //ok
    TEST_BITMAP_Match_SrcIPv4_NotFound();       //ok
    TEST_BITMAP_Match_SrcIPv4_Modify();         //ok
    TEST_BITMAP_Match_SrcIPv4_ModifySpeed();    //ok
#endif

// BITMAP_Match_DestIPv4
#if 0
    TEST_BITMAP_Match_DestIPv4_Any();           //ok
    TEST_BITMAP_Match_DestIPv4_NoModify();      //ok
    TEST_BITMAP_Match_DestIPv4_NotFound();      //ok
    TEST_BITMAP_Match_DestIPv4_Modify();        //ok
    TEST_BITMAP_Match_DestIPv4_ModifySpeed();   //ok
#endif

// Random_Quick_Match
#if 0
    //TEST_Random_Quick_Match_Obj();
    //TEST_Random_Bitmap_Match_Obj();
    //TEST_Random_Quick_Match_IPv4();
    //TEST_Random_Bitmap_Match_SrcIPv4();//ok
#endif

#if 0
    TEST_Random_Bitmap_Match_DestIPv4();        //ok
#endif

// Random_Quick_Match_Speed
#if 1
    //TEST_Random_Quick_Match_Obj_Speed();
    //TEST_Random_Bitmap_Match_Obj_Speed();
    //TEST_Random_Quick_Match_IPv4_Speed();
    //TEST_Random_Bitmap_Match_SrcIPv4_Speed();//ok
#endif

#if 0
    TEST_Random_Bitmap_Match_DestIPv4_Speed();  //ok
#endif

// SWIFT_Valgrind_MemoryLeak
#if 1
    TEST_SWIFT_Valgrind_MemoryLeak();
#endif

#if 1
    //TEST_FORMAL_QUICK_Match_Obj_Point();
    //TEST_FORMAL_QUICK_Match_IPv4_Point();
    //TEST_FORMAL_QUICK_Match_Obj_IPv4();
#endif

    return 0;
}
